﻿<UserControl x:Class="NthDownload.Views.QueueView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:behaviors="clr-namespace:NthDownload.Common.Interactivity.Behaviors;assembly=NthDownload.Common"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" 
             MinHeight="300" MinWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <StackPanel Grid.Row="0" Grid.Column="0" Margin="0,0,5,0">
            <Button x:Name="AddDownloads" Content="Add" Margin="0,0,0,10"/>
            <Button x:Name="DisplayActiveDownloads" Content="Active" Margin="0,0,0,5"/>
            <Button x:Name="DisplayInactiveDownloads" Content="Inactive" Margin="0,0,0,5" />
            <Button x:Name="DisplayArchivedDownloads" Content="Archived" Margin="0,0,0,5"/>
        </StackPanel>
        
        <ListBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding DownloadsViewSource.View}" SelectionMode="Extended"
                 HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0">        
            <i:Interaction.Behaviors>
                <behaviors:ListBoxSelectedItemsBinder SelectedItems="{Binding SelectedDownloads, Mode=TwoWay}" />
                <behaviors:ListBoxScrollOffsetBinder VerticalOffset="{Binding VerticalOffset, Mode=TwoWay}" HorizontalOffset="{Binding HorizontalOffset, Mode=TwoWay}" />
            </i:Interaction.Behaviors>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                            <TextBlock Text="{Binding Position}" />
                            <TextBlock Text=" - " />
                            <TextBlock Text="{Binding Status}" />
                            <TextBlock Text=" - " />
                            <TextBlock Text="{Binding Path}" />
                            <TextBlock Text=" - " />
                            <TextBlock Text="{Binding DownloadedAmount}" />
                        </StackPanel>
                        
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button Content="Start" cal:Message.Attach="[Event Click] = [Action StartDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>

                            <Button Content="Pause" cal:Message.Attach="[Event Click] = [Action PauseDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>

                            <Button Content="Stop" cal:Message.Attach="[Event Click] = [Action StopDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>

                            <Button Content="Remove" cal:Message.Attach="[Event Click] = [Action RemoveDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>

                            <Button Content="Up" cal:Message.Attach="[Event Click] = [Action MoveUpDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>

                            <Button Content="Down" cal:Message.Attach="[Event Click] = [Action MoveDownDownloads($dataContext)]" Margin="0,0,5,0" 
                                    Style="{StaticResource ListBoxMouseOverButton}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</UserControl>
